//
//  Util.m
//  HNLogistics
//
//  Created by 蒋宇 on 14/12/1.
//  Copyright (c) 2014年 蒋宇. All rights reserved.
//

#import <MBProgressHUD.h>
#import "Util.h"
#import "LoginViewC.h"

@implementation Util

+ (void)showHud:(NSString *)title {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication] keyWindow]
                                              animated:YES];
    hud.labelText = title;
    [hud hide:YES afterDelay:.5f];
}

+ (UIViewController *)controllerFromMainStoryboardWithIdentifierID:(NSString *)identifierID {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
                                                         bundle:nil];
    return [storyboard instantiateViewControllerWithIdentifier:identifierID];
}

+ (void)presentNaviC:(UIViewController *)sourceC fromController:(UIViewController *)fromC
{
    UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:sourceC];
    navc.navigationBar.translucent = NO;
    [fromC presentViewController:navc animated:YES completion:nil];
  
}

+ (void)presentLoginControllerFromViewController:(UIViewController *)con {
    LoginViewC *loginvc = [[LoginViewC alloc]
                           initWithNibName:@"LoginViewC"
                           bundle:nil];
    [Util presentNaviC:loginvc fromController:con];
}


+ (void)changeNSString:(NSString *)str{
    str = [str stringByTrimmingCharactersInSet:
           [NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

+(NSString *)getstrWithsportEventId:(NSString *)sportEventId{
    NSString *idNum = [sportEventId copy];
    NSString *type;
    switch ([idNum intValue]) {
        case 1:
            type = @"羽毛球";
            break;
        case 2:
            type = @"乒乓球";
            break;
        case 3:
            type = @"足球";
            break;
        case 4:
            type = @"篮球";
            break;
        case 5:
            type = @"网球";
            break;
        case 6:
            type = @"台球";
            break;
        case 7:
            type = @"钓鱼";
            break;
        case 8:
            type = @"攀岩";
            break;
        default:
            break;
    }

    return type;
}

+(NSString *)getstrWithstarNum:(NSString *)starNum{
    NSString *level = [starNum copy];
    NSString *number;
    switch ([level intValue]) {
        case 0:
            number = @"nostar.png";
            break;
        case 1:
            number = @"onestar.png";
            break;
        case 2:
            number = @"twostar.png";
            break;
        case 3:
            number = @"threestar.png";
            break;
        case 4:
            number = @"fourstar.png";
            break;
        case 5:
            number = @"allstar.png";
            break;
        default:
            break;
    }
    return number;
}

+(NSString *)getstrWithSex:(NSString *)sex{
    
    NSString *gsex = [sex copy];
    NSString *bsex;
    switch ([gsex intValue]) {
        case 1:
            bsex = @"男";
            break;
        case 2:
            bsex = @"女";
            break;
        default:
            break;
    }
    return bsex;
}

+(NSString *)getsexWithImg:(NSString *)Img{
    NSString *gsex = [Img copy];
    NSString *bsex;
    switch ([gsex intValue]) {
        case 1:
            bsex = @"boyimage";
            break;
        case 2:
            bsex = @"grilimage";
            break;
        default:
            break;
    }
    return bsex;
}

+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"Sunday", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:
                            NSGregorianCalendar];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:
                            @"Asia/Changzhou"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit *calendarUnit = NSWeekdayCalendarUnit;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
}

+ (NSString*)serviceItem:(NSString *)serviceItem{
    NSString *item = [serviceItem copy];
    NSString *img;
    switch ([item intValue]) {
        case 1:
            img = @"cgshower.png";
            break;
        case 2:
            img = @"cgpark.png";
            break;
        case 3:
            img = @"cgcard.png";
            break;
        case 4:
            img = @"cgbox.png";
            break;
        case 5:
            img = @"cgsell.png";
            break;
        case 6:
            img = @"cgmember.png";
            break;
        case 7:
            img = @"cgrelax.png";
            break;
        case 8:
            img = @"cgbowwer.png";
            break;
        case 9:
            img = @"cgwifi.png";
            break;
        default:
            break;
    }
    return img;
}

+ (NSString*)serviceStr:(NSString *)serviceStr{
    NSString *item = [serviceStr copy];
    NSString *str;
    switch ([item intValue]) {
        case 1:
            str = @"洗浴";
            break;
        case 2:
            str = @"停车";
            break;
        case 3:
            str = @"刷卡";
            break;
        case 4:
            str = @"储物";
            break;
        case 5:
            str = @"场地卖品";
            break;
        case 6:
            str = @"会员卡";
            break;
        case 7:
            str = @"休息区";
            break;
        case 8:
            str = @"器材租借";
            break;
        case 9:
            str = @"wifi";
            break;
        default:
            break;
    }
    return str;
}

+ (NSString*)levelWithstr:(NSString *)str{
    NSString *lstr = [str copy];
    NSString *restr;
    switch ([lstr intValue]) {
        case 1:
            restr = @"初级";
            break;
        case 2:
            restr = @"中级";
            break;
        case 3:
            restr = @"高级";
            break;
        default:
            break;
    }
    return restr;
}

+ (NSString*)strWithlevel:(NSString *)level{
    NSString *str = [level copy];
    NSString *new;
    if ([str isEqualToString:@"初级"]) {
        new =@"1";
        return new;
    }
    if ([str isEqualToString:@"中级"]) {
        new =@"2";
        return new;
    }
   else {
        new =@"3";
        return new;
    }
}

+ (UIButton *)warBtnWithNum:(NSString *)Num{
    NSString *num = [Num copy];
    UIButton *warBtn;
    if ([num isEqualToString:@"1"]) {
        [warBtn setTitle:@"达成" forState:UIControlStateNormal];
        [warBtn setBackgroundColor:RGBCOLOR(250, 141, 69)];
        return warBtn;
    }
    if ([num isEqualToString:@"2"]) {
        [warBtn setTitle:@"审核" forState:UIControlStateNormal];
        [warBtn setBackgroundColor:RGBCOLOR(189, 189, 189)];
        return warBtn;
    }
    else {
        [warBtn setTitle:@"取消" forState:UIControlStateNormal];
        [warBtn setBackgroundColor:RGBCOLOR(189, 189, 189)];
        return warBtn;
    }

}

@end
